package com.tangruojie.domain.query;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

@Data
public class PageQuery {

    /**
     * 当前页码
     */
    private Integer pageNum = 1;
    /**
     * 每页数量
     */
    private Integer pageSize = 5;
    /**
     * 排序字段
     */
    private String sortProperty;
    /**
     * 排序方式
     */
    private Boolean order = true;

    /**
     * 构建分页参数
     *
     * @param <T>
     * @return
     */
    public <T> Page<T> buildPage() {
        Page<T> page = new Page<>(pageNum, pageSize);
        if (sortProperty != null) {
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn(sortProperty);
            orderItem.setAsc(order);
            page.addOrder(orderItem);
        }
        return page;
    }

}
